using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class PSDetJobMap : EntityTypeConfiguration<PSDetJob>
    {
        public PSDetJobMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Item)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.AssignedToV)
                .HasMaxLength(6);

            this.Property(t => t.VendInvNo)
                .HasMaxLength(8);

            this.Property(t => t.PDBatch)
                .HasMaxLength(8);

            this.Property(t => t.Note)
                .HasMaxLength(200);

            this.Property(t => t.vpdbatch)
                .HasMaxLength(8);

            // Table & Column Mappings
            this.ToTable("PSDetJobs");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.PsDetID).HasColumnName("PsDetID");
            this.Property(t => t.DateOrdered).HasColumnName("DateOrdered");
            this.Property(t => t.Item).HasColumnName("Item");
            this.Property(t => t.Classification).HasColumnName("Classification");
            this.Property(t => t.AssignedToW).HasColumnName("AssignedToW");
            this.Property(t => t.AssignedToV).HasColumnName("AssignedToV");
            this.Property(t => t.Duration).HasColumnName("Duration");
            this.Property(t => t.InitDDate).HasColumnName("InitDDate");
            this.Property(t => t.UpDDate).HasColumnName("UpDDate");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.UnitCost).HasColumnName("UnitCost");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.Total).HasColumnName("Total");
            this.Property(t => t.VendInvNo).HasColumnName("VendInvNo");
            this.Property(t => t.VendInvDate).HasColumnName("VendInvDate");
            this.Property(t => t.PDBatch).HasColumnName("PDBatch");
            this.Property(t => t.ApGenerated).HasColumnName("ApGenerated");
            this.Property(t => t.Note).HasColumnName("Note");
            this.Property(t => t.VAT).HasColumnName("VAT");
            this.Property(t => t.vpdbatch).HasColumnName("vpdbatch");

            // Relationships
            this.HasRequired(t => t.Item1)
                .WithMany(t => t.PSDetJobs)
                .HasForeignKey(d => d.Item);
            this.HasRequired(t => t.Psdet)
                .WithMany(t => t.PSDetJobs)
                .HasForeignKey(d => d.PsDetID);
            this.HasOptional(t => t.TaskStatu)
                .WithMany(t => t.PSDetJobs)
                .HasForeignKey(d => d.Status);
            this.HasOptional(t => t.Vend)
                .WithMany(t => t.PSDetJobs)
                .HasForeignKey(d => d.AssignedToV);
            this.HasOptional(t => t.Worker)
                .WithMany(t => t.PSDetJobs)
                .HasForeignKey(d => d.AssignedToW);

        }
    }
}
